package com.zhiche.lisa.lspm.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.core.utils.Account.AccountUtil;
import com.zhiche.lisa.core.utils.Account.JwtAccountVO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarAndDriverInfoLineBO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarrierDriverBO;
import com.zhiche.lisa.lspm.dao.model.driver.Driver;
import com.zhiche.lisa.lspm.dao.model.driver.DriverBankAccount;
import com.zhiche.lisa.lspm.dao.model.driver.bo.*;
import com.zhiche.lisa.lspm.dao.model.trailer.bo.ChangeTrailerPlateBO;
import com.zhiche.lisa.lspm.dto.*;
import com.zhiche.lisa.lspm.service.driver.IDriverBankAccountService;
import com.zhiche.lisa.lspm.service.driver.IDriverCheckinService;
import com.zhiche.lisa.lspm.service.driver.IDriverService;
import com.zhiche.lisa.lspm.service.utils.IntegrationUtil;
import com.zhiche.lisa.lspm.vo.common.CommonVo;
import com.zhiche.lisa.lspm.vo.common.OriginationCityVO;
import com.zhiche.lisa.lspm.vo.driver.*;
import com.zhiche.lisa.lspm.vo.lsp.LspSubVo;
import com.zhiche.lisa.lspm.vo.vehicle.CarAndDriverInfoLineVO;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 司机 接口
 *
 * @author lbl
 * @since 2018-05-28
 */
@RestController
@RequestMapping(value = "/driver")
@Api(value = "/driver", description = "司机接口", tags = {"司机接口"})
public class DriverController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DriverController.class);

    @Autowired
    private IDriverService driverService;
    @Autowired
    private IDriverCheckinService driverCheckinService;
    @Autowired
    private IDriverBankAccountService driverBankAccountService;
    @Autowired
    private IntegrationUtil integrationUtil;

    @PostMapping(value = "/driverLine")
    @ApiOperation(value = "获取司机列表", notes = "获取司机列表", produces = MediaType.APPLICATION_JSON_VALUE,
            response = RestfulResponse.class)
    public RestfulResponse<Page<DriverLineVO>> driverLine(@RequestBody Page<DriverLineBO> page) {
        LOGGER.info("DriverController.driverLine（获取司机列表） params : {} ", page);

        RestfulResponse<Page<DriverLineVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS
                .getCode(), CommonEnum.SUCCESS.getText(), null);

        try {
            Page<DriverLineVO> pageVo = driverService.driverLine(page);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("DriverController.driverLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.driverLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/authedDriverLine")
    @ApiOperation(value = "认证的司机列表", notes = "认证的司机列表", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<DriverLineVO>> authedDriverLine(@RequestBody Page<DriverLineBO>
                                                                        page) {
        LOGGER.info("DriverController.authedDriverLine（获取认证的司机列表） params : {} ", page);

        RestfulResponse<Page<DriverLineVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS
                .getCode(), CommonEnum.SUCCESS.getText(), null);

        try {
            Page<DriverLineVO> pageVo = driverService.authedDriverLine(page);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("DriverController.authedDriverLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.authedDriverLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }

        return result;
    }


    @GetMapping(value = "/findModifyInfo")
    @ApiOperation(value = "查找编辑司机信息", notes = "查找编辑司机信息", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<ModifyDriverBO> findModifyInfo(Long id) {
        LOGGER.info("DriverController.findModifyInfo（查找编辑司机信息） params : {} ", id);

        RestfulResponse<ModifyDriverBO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode
                (), CommonEnum.SUCCESS.getText(), null);

        try {
            if (id == null) return null;
            ModifyDriverBO modifyDriverBO = driverService.findModifyInfo(id);
            result.setData(modifyDriverBO);
        } catch (BaseException e) {
            LOGGER.error("DriverController.findModifyInfo ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.findModifyInfo ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }

        return result;
    }

    @PostMapping(value = "/getDriverByLsp")
    @ApiOperation(value = "获取承运商下的司机", notes = "获取承运商下的司机", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<DriverLineVO>> getDriverByLsp(@RequestBody Page<DriverLineVO> page) {
        //Long lspId, Boolean isAuth
        LOGGER.info("DriverController.getDriverByLsp（获取承运商下的司机） params : {} ", page);

        RestfulResponse<Page<DriverLineVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(driverService.getDriverByLsp(page));
        } catch (BaseException e) {
            LOGGER.error("DriverController.getDriverByLsp ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.getDriverByLsp ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }

        return result;
    }

    @PostMapping(value = "/carAndDriverInfoLine")
    @ApiOperation(value = "获取车辆与司机关系列表", notes = "获取车辆与司机关系列表", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<CarAndDriverInfoLineVO>> carAndDriverInfoLine(@RequestBody Page<CarAndDriverInfoLineBO> page) {
        LOGGER.info("DriverController.carAndDriverInfoLine（获取车辆与司机关系列表） params : {} ", page);

        RestfulResponse<Page<CarAndDriverInfoLineVO>> result = new RestfulResponse<>(CommonEnum
                .SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(driverService.carAndDriverInfoLine(page));
        } catch (BaseException e) {
            LOGGER.error("DriverController.carAndDriverInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.carAndDriverInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/changeTrailerPlate")
    @ApiOperation(value = "更改挂车车牌号", notes = "更改挂车车牌号", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse changeTrailerPlate(@RequestBody ChangeTrailerPlateBO
                                                      changeTrailerPlateBO) {
        LOGGER.info("DriverController.changeTrailerPlate（更改挂车车牌号） params : {} ",
                changeTrailerPlateBO.toString());

        RestfulResponse result = null;

        try {
            result = new RestfulResponse(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText
                    (), null);
        } catch (BaseException e) {
            LOGGER.error("DriverController.changeTrailerPlate ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.changeTrailerPlate ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }

        return result;
    }

    @PostMapping(value = "/discontinuatDriver")
    @ApiOperation(value = "停用司机", notes = "停用司机", produces = MediaType.APPLICATION_JSON_VALUE,
            response = RestfulResponse.class)
    public RestfulResponse<List<String>> discontinuatDriver(@RequestBody CommonVo commonBO, @RequestHeader("Authorization") String token) {
        LOGGER.info("CarrierController.discontinuatDriver（停用司机） params : {} ", commonBO.toString
                ());
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<String> msgs = driverService.discontinuatDriver(commonBO.getDriverIds(), token);
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分停用失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.discontinuatDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.discontinuatDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/enableDriver")
    @ApiOperation(value = "启用司机", notes = "启用司机", produces = MediaType.APPLICATION_JSON_VALUE,
            response = RestfulResponse.class)
    public RestfulResponse<List<String>> enableDriver(@RequestBody CommonVo commonBO, @RequestHeader("Authorization") String token) {
        LOGGER.info("CarrierController.enableDriver（启用司机） params : {} ", commonBO.toString());
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<String> msgs = driverService.enableDriver(commonBO.getDriverIds(), token);
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分启用失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.enableDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.enableDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/authDriver")
    @ApiOperation(value = "认证司机", notes = "认证司机", produces = MediaType.APPLICATION_JSON_VALUE,
            response = RestfulResponse.class)
    public RestfulResponse authDriver(@RequestBody CommonVo commonBO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("DriverController.authDriver（停用牵引车） params : {} ", commonBO.toString());
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<String> msg = driverService.batchUpdateAuthStatusByIds(commonBO.getDriverIds(), authorization);
            if (!CollectionUtils.isEmpty(msg)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分认证失败", msg);
            }

        } catch (BaseException e) {
            LOGGER.error("DriverController.authDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.authDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/cancelAuthDriver")
    @ApiOperation(value = "取消认证司机", notes = "取消认证司机", produces = MediaType.APPLICATION_JSON_VALUE,
            response = RestfulResponse.class)
    public RestfulResponse cancelAuthDriver(@RequestBody CommonVo commonVo) {
        LOGGER.info("DriverController.cancelAuthCarrier（停用牵引车） params : {} ", commonVo.toString());
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            driverService.batchUpdateCancelAuthStatusByIds(commonVo.getDriverIds());
        } catch (BaseException e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/driverCheckinLine")
    @ApiOperation(value = "获取司机报班记录列表", notes = "获取司机报班记录列表", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<DriverCheckinLineVO>> driverCheckinLine(@RequestBody Page<DriverCheckinLineBO> page) {
        LOGGER.info("DriverController.driverCheckinLine（获取司机报班记录列表） params : {} ", page);
        RestfulResponse<Page<DriverCheckinLineVO>> result = new RestfulResponse<>(CommonEnum
                .SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(driverCheckinService.driverCheckinLine(page));
        } catch (BaseException e) {
            LOGGER.error("DriverController.driverCheckinLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.driverCheckinLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/driverCancelCheckinLine")
    @ApiOperation(value = "获取司机取消报班记录列表", notes = "获取司机取消报班记录列表", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<DriverCheckinLineVO>> driverCancelCheckinLine(@RequestBody Page<DriverCheckinLineBO> page) {
        LOGGER.info("DriverController.driverCancelCheckinLine（获取司机取消报班记录列表） params : {} ", page);
        RestfulResponse<Page<DriverCheckinLineVO>> result = new RestfulResponse<>(CommonEnum
                .SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(driverCheckinService.driverCancelCheckinLine(page));
        } catch (BaseException e) {
            LOGGER.error("DriverController.driverCancelCheckinLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.driverCancelCheckinLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/authDriverCheck")
    @ApiOperation(value = "审核取消报班", notes = "审核取消报班", produces = MediaType.APPLICATION_JSON_VALUE,
            response = RestfulResponse.class)
    public RestfulResponse authDriverCheck(@RequestBody CommonVo commonVo, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("DriverController.authDriverCheck（审核取消报班） params : {} ", commonVo.toString());
        RestfulResponse result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), false);
        try {
            result.setData(driverCheckinService.authDriverCheckIn(commonVo.getIds(), authorization));
        } catch (BaseException e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), false);
        } catch (Exception e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    false);
        }
        return result;
    }


    @ApiOperation(value = "查询获取司机与牵引车列表", notes = "查询获取司机与牵引车列表", produces = MediaType
            .APPLICATION_JSON_VALUE)
    @PostMapping(value = "/driverCarrier")
    public RestfulResponse<Page<DriverCarrierBO>> queryDriverCarrier(@RequestBody Page<DriverCarrierBO> page,
                                                                     @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（获取牵引车与挂车列表） params : {} ", page);
        RestfulResponse<Page<DriverCarrierBO>> result = new RestfulResponse<>(CommonEnum.SUCCESS
                .getCode(), CommonEnum.SUCCESS.getText(), null);

        try {
            Page<DriverCarrierBO> pageVo = driverService.queryPageDriverCarrier(page, authorization);
            result.setData(pageVo);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }


    @ApiOperation(value = "获取司机可绑定的牵引车", notes = "获取司机可绑定的牵引车", produces = MediaType
            .APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "driverId", value = "牵引车ID", required = true, dataType =
                    "Long"),
            @ApiImplicitParam(name = "carrierPlate", value = "挂车车牌", required = true, dataType =
                    "String")})
    @PostMapping(value = "/usableCarrier")
    public RestfulResponse<List<CarrierDriverBO>> queryUsableCarrier(@RequestBody DriverCarrierVo driverCarrierVo) {
        LOGGER.info("CarrierController.carrierInfoLine（获取司机的可用牵引车） params : {} ", driverCarrierVo);

        RestfulResponse<List<CarrierDriverBO>> result = new RestfulResponse<>(CommonEnum.SUCCESS
                .getCode(), CommonEnum.SUCCESS.getText(), null);

        try {
            List<CarrierDriverBO> listData = driverService.queryUsableCarrier
                    (driverCarrierVo.getDriverId(), driverCarrierVo.getCarrierPlate());
            result.setData(listData);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @ApiOperation(value = "司机绑定牵引车", notes = "司机绑定牵引车", produces = MediaType
            .APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "driverId", value = "司机ID", required = true, dataType =
                    "Long"),
            @ApiImplicitParam(name = "carrierId", value = "牵引车ID", required = true, dataType =
                    "Long")})
    @PostMapping(value = "/bindCarrier")
    public RestfulResponse<Boolean> bindCarrier(@RequestBody DriverCarrierVo driverCarrierVo, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（绑定司机与牵引车） params : {}", driverCarrierVo);

        RestfulResponse<Boolean> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(),
                null);
        try {
            Boolean bool = driverService.bingCarrier(driverCarrierVo.getDriverId(),
                    driverCarrierVo.getCarrierId(), driverCarrierVo.getTenantId(), authorization);
            result.setData(bool);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }


    @ApiOperation(value = "解绑司机与牵引车", notes = "解绑司机与牵引车", produces = MediaType
            .APPLICATION_JSON_VALUE)
    @PostMapping(value = "/unbindCarrier")
    public RestfulResponse<Boolean> unbindCarrier(@RequestBody DriverCarrierVo driverCarrierVo, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.carrierInfoLine（解绑司机与牵引车） params : {} ", driverCarrierVo);
        RestfulResponse<Boolean> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(),
                null);
        try {
            for (DriverCarrierBO driverCarrierBO : driverCarrierVo.getDriverCarriers()) {
                driverService.unbingCarrier(driverCarrierBO.getId(), driverCarrierBO.getCarrierId
                        (), authorization);
            }
            result.setData(true);
        } catch (BaseException e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.carrierInfoLine ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

    @PostMapping(value = "/deleteDriver")
    @ApiOperation(value = "删除司机", notes = "删除司机", produces = MediaType.APPLICATION_JSON_VALUE, response =
            RestfulResponse.class)
    public RestfulResponse<List<String>> deleteDriver(@RequestBody CommonVo commonVo,
                                                      @RequestHeader("Authorization") String token) {
        LOGGER.info("CarrierController.cancelAuthCarrier（删除司机） params : {} ", commonVo.toString());
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<String> msgs = driverService.deleteByIds(commonVo.getDriverIds(), token);
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分司机删除失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("CarrierController.cancelAuthCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    //---来源于原driver

    /**
     * 更新司机信息
     *
     * @param driverVO
     * @return
     */
    @RequestMapping(value = "/updateDriver", method = RequestMethod.POST)
    @ApiOperation(value = "更新司机信息", notes = "更新司机信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> updateDriver(@RequestBody DriverVO driverVO) {
        LOGGER.info("DriverController.updateDriver param: {}", driverVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            DriverBO driverBO = new DriverBO();
            BeanUtils.copyProperties(driverVO, driverBO);
            driverService.updateDriver(driverBO);
        } catch (BaseException be) {
            LOGGER.error("DriverController.updateDriver error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.updateDriver error:{}", e.getMessage());
            result.setMessage("更新司机失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @RequestMapping(value = "/updateDriverAttach", method = RequestMethod.POST)
    @ApiOperation(value = "更新司机附件信息", notes = "更新司机附件信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> updateDriverAttach(@RequestBody AttachVO driverAttachVO,
                                                      @RequestHeader("Authorization") String authorization) {
        LOGGER.info("DriverController.updateDriverAttach param: {}", driverAttachVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            driverService.updateDriverAttach(driverAttachVO, authorization);
        } catch (BaseException be) {
            LOGGER.error("DriverController.updateDriverAttach error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.updateDriverAttach error:{}", e.getMessage());
            result.setMessage("更新司机失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }


    /**
     * 获取司机信息
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/getDriver/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "获取司机信息", notes = "获取司机信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<DriverVO> getDriver(@PathVariable Long id) {
        LOGGER.info("DriverController.getDriver param: {}", id);
        RestfulResponse<DriverVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            DriverBO driverBO = driverService.getDriverById(id);
            DriverVO driverVO = new DriverVO();
            BeanUtils.copyProperties(driverBO, driverVO);
            result.setData(driverVO);
        } catch (BaseException be) {
            LOGGER.error("DriverController.getDriver error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.getDriver error:{}", e.getMessage());
            result.setMessage("获取司机失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    /**
     * 司机报班
     */
    @RequestMapping(value = "/checkin", method = RequestMethod.POST)
    @ApiOperation(value = "司机报班", notes = "司机报班", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> checkin(@RequestBody DriverAddCheckinVO driverCheckinVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("DriverController.checkin param: {}", driverCheckinVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            DriverCheckinBO driverCheckinBO = new DriverCheckinBO();
            BeanUtils.copyProperties(driverCheckinVO, driverCheckinBO);
            driverCheckinService.checkin(driverCheckinBO, authorization);
        } catch (BaseException be) {
            LOGGER.error("DriverController.checkin error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.checkin error:{}", e.getMessage());
            result.setMessage("司机报班失败,系统异常");
            result.setCode(-1);
        }
        return result;
    }

    /**
     * 车辆报班 - 新增报班
     */
    @PostMapping("/insertNewCheckIn")
    public RestfulResponse<Page<DriverCheckinDTO>> insertNewCheckIn(@RequestBody DriverCheckinDTO dto,
                                                                    @RequestHeader("Authorization") String token) {
        RestfulResponse<Page<DriverCheckinDTO>> response = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        LOGGER.info("DriverController.insertNewCheckIn param: {}", JSONObject.toJSONString(dto));

        try {
            driverCheckinService.insertNewCheckIn(dto, token);
        } catch (BaseException be) {
            LOGGER.error("DriverController.insertNewCheckIn BaseException {}", be);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.insertNewCheckIn error {}", e);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(CommonEnum.ERROR.getText());
        }
        return response;
    }

    /**
     * 司机报班信息获取
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/getCheckin", method = RequestMethod.POST)
    @ApiOperation(value = "司机报班信息获取", notes = "司机报班信息获取", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<DriverCheckinVO>> getCheckin(@RequestBody Page<DriverCheckinBO> page) {
        LOGGER.info("DriverController.checkin param: {}", page);
        RestfulResponse<Page<DriverCheckinVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            Page<DriverCheckinVO> pageVo = driverCheckinService.getChekin(page);
            result.setData(pageVo);
        } catch (BaseException be) {
            LOGGER.error("DriverController.checkin error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.checkin error:{}", e.getMessage());
            result.setMessage("司机报班信息获取失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    /**
     * 取消报班
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/cancelCheckin", method = RequestMethod.POST)
    @ApiOperation(value = "取消报班", notes = "取消报班", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> cancelCheckin(@RequestBody DriverCheckinVO driverCheckinVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("DriverController.cancelCheckin param: {}", driverCheckinVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            DriverCheckinBO driverCheckinBO = new DriverCheckinBO();
            BeanUtils.copyProperties(driverCheckinVO, driverCheckinBO);
            driverCheckinService.cancelChekin(driverCheckinBO, authorization);
        } catch (BaseException be) {
            LOGGER.error("DriverController.cancelCheckin error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.cancelCheckin error:{}", e.getMessage());
            result.setMessage("司机取消报班失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    /**
     * otm取消报班
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/otmCancelCheckin", method = RequestMethod.POST)
    @ApiOperation(value = "otm取消报班", notes = "otm取消报班", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> otmCancelCheckin(@RequestBody OtmCheckinVO otmCheckinVO) {
        LOGGER.info("DriverController.cancelCheckin param: {}", otmCheckinVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            driverCheckinService.otmCancelChekin(otmCheckinVO);
        } catch (BaseException be) {
            LOGGER.error("DriverController.cancelCheckin error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.cancelCheckin error:{}", e.getMessage());
            result.setMessage("otm取消报班,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @RequestMapping(value = "/checkInNonAudited", method = RequestMethod.POST)
    @ApiOperation(value = "直接取消报班", notes = "直接取消报班", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> checkInNonAudited(@RequestBody DriverCheckinVO driverCheckinVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("DriverController.checkInNonAudited param: {}", driverCheckinVO);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            DriverCheckinBO driverCheckinBO = new DriverCheckinBO();
            BeanUtils.copyProperties(driverCheckinVO, driverCheckinBO);
            driverCheckinService.checkInNonAudited(driverCheckinBO, authorization);
        } catch (BaseException be) {
            LOGGER.error("DriverController.checkInNonAudited error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.checkInNonAudited error:{}", e.getMessage());
            result.setMessage("司机取消报班失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    /**
     * 获取司机认证状态
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/getDriverCertification/{drivertId}", method = RequestMethod.GET)
    @ApiOperation(value = "获取司机认证状态", notes = "获取司机认证状态", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = DriverCertificationBO.class), @ApiResponse(code = -1, message = "获取司机认证信息失败,系统异常", response = Objects.class)}
    )
    public RestfulResponse<DriverCertificationBO> getDriverCertification(@PathVariable @ApiParam(name = "drivertId", value = "司机ID", required = true) Long drivertId) {
        LOGGER.info("DriverController.getDriverCertification param: {}", drivertId);
        RestfulResponse<DriverCertificationBO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            DriverCertificationBO driverCertificationBO = driverService.getDriverCertification(drivertId);
            result.setData(driverCertificationBO);
        } catch (BaseException be) {
            LOGGER.error("DriverController.getDriverCertification error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.getDriverCertification error:{}", e.getMessage());
            result.setMessage("获取司机认证信息失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    /**
     * 根据司机手机号登陆
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/login/{mobile}", method = RequestMethod.GET)
    @ApiOperation(value = "根据司机手机号登陆", notes = "根据司机手机号登陆", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<DriverVO> login(@PathVariable String mobile) {
        LOGGER.info("DriverController.login param: {}", mobile);
        RestfulResponse<DriverVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            DriverBO driverBO = driverService.loginDriver(mobile);
            DriverVO driverVO = new DriverVO();
            BeanUtils.copyProperties(driverBO, driverVO);
            result.setData(driverVO);
        } catch (BaseException be) {
            LOGGER.error("DriverController.login error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.login error:{}", e.getMessage());
            result.setMessage("登陆失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @PostMapping(value = "/registDriver")
    @ApiOperation(value = "注册司机", notes = "注册司机",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> regist(@RequestBody RegistDriverVO registDriverVO) {
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            driverService.registDriver(registDriverVO);
        } catch (BaseException be) {
            LOGGER.error("RegistDriverController.add error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("RegistDriverController.add error:{}", e.getMessage());
            result.setMessage("注册司机失败,系统异常");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }


    @PostMapping(value = "/updateDriverBasic")
    @ApiOperation(value = "更改司机基础信息", notes = "更改司机基础信息", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Driver> updateDriver(@RequestBody DriverBasicVO driver, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("DriverController.updateDriver" +
                "（更改司机基础信息） params : {} ", driver.toString());
        RestfulResponse<Driver> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Driver driverResult = driverService.updateDriver(driver, authorization);
            result.setData(driverResult);
        } catch (BaseException e) {
            LOGGER.error("DriverController.updateDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.updateDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getDriverBasic")
    @ApiOperation(value = "获取司机", notes = "获取司机", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<DriverBasicVO> getDriverBasic(Long driverId) {
        LOGGER.info("CarrierController.getDriver（获取司机） params : {} ", driverId);
        RestfulResponse<DriverBasicVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {

            result.setData(driverService.getDriverInfoLine(driverId));
        } catch (BaseException e) {
            LOGGER.error("DriverController.getDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.getCarrier ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getBank")
    @ApiOperation(value = "获取银行卡", notes = "获取银行卡", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<List<DriverBankAccount>> getBank(Long driverId) {
        LOGGER.info("CarrierController.getBank（获取银行卡） params : {} ", driverId);
        RestfulResponse<List<DriverBankAccount>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            EntityWrapper driverBankew = new EntityWrapper<>();
            driverBankew.eq("driver_id", driverId);
            result.setData(driverBankAccountService.selectList(driverBankew));
        } catch (BaseException e) {
            LOGGER.error("DriverController.getBank ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.getBank ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/updateBank")
    @ApiOperation(value = "更新银行卡", notes = "更新银行卡", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<String> updateBank(@RequestBody DriverBankVO driverBankVO) {
        LOGGER.info("DriverController.updateBank（更新银行卡） params : {} ", driverBankVO);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            for (DriverBankAccount driverBankAccount :
                    driverBankVO.getDriverBankAccounts()) {
                if (Objects.nonNull(driverBankAccount.getId())) {
                    driverBankAccountService.updateById(driverBankAccount);
                } else {
                    driverBankAccount.setDriverId(driverBankVO.getDriverId());
                    JwtAccountVO jwtAccount = AccountUtil.getAccountInfoFromSecurityContext();
                    driverBankAccount.setGmtCreate(new Date());
                    if (Objects.nonNull(jwtAccount)) {
                        driverBankAccount.setCreator(jwtAccount.getAccountId());
                    }
                    driverBankAccountService.insert(driverBankAccount);
                }
            }
        } catch (BaseException e) {
            LOGGER.error("DriverController.updateBank ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.updateBank ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/openDriver")
    @ApiOperation(value = "自动开通司机", notes = "自动开通司机", produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<String> openDriver(@RequestBody DriverAccountVO driverAccountVO, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("CarrierController.openDriver（开通司机） params : {}", driverAccountVO);
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),
                null);
        try {
            if (Objects.isNull(driverAccountVO.getId())) throw new BaseException("未匹配需要开通的司机");
            driverService.driverSendMessage(driverService.selectByIdNoTenant(driverAccountVO.getId()), authorization);
        } catch (BaseException e) {
            LOGGER.error("DriverController.openDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.openDriver ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/openDriverAccountList")
    @ApiOperation(value = "开通司机账号列表", notes = "开通司机账号列表",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> openDriverAccountList(@RequestBody Page<Driver> page, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("RegistDriverController.openDriverAccountList params:{}", "开通司机账号列表");
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            result.setData(driverService.openDriverList(page, authorization));
        } catch (BaseException be) {
            LOGGER.error("RegistDriverController.openDriverAccountList error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("RegistDriverController.openDriverAccountList error:{}", e.getMessage());
            result.setMessage("操作失败");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @PostMapping(value = "/transferDriver")
    @ApiOperation(value = "转移司机", notes = "转移司机",
            produces = MediaType.APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Object> transferDriver(@RequestBody LspSubVo lspSubVo, @RequestHeader("Authorization") String authorization) {
        LOGGER.info("RegistDriverController.transferDriver params:{}", lspSubVo);
        RestfulResponse<Object> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            result.setData(driverService.transferDriver(lspSubVo.getIds(), lspSubVo.getLspId(), lspSubVo.getIsAllTransfer(), authorization));
        } catch (BaseException be) {
            LOGGER.error("RegistDriverController.transferDriver error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("RegistDriverController.transferDriver error:{}", e.getMessage());

        }
        return result;
    }

    @GetMapping(value = "/getOriginCity")
    @ApiOperation(value = "获取报班起运城市", notes = "获取报班起运城市", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = OriginationCityVO.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<OriginationCityVO>> getOriginCity(@ApiParam(name = "cityName", value = "查询城市", required = true) String cityName) {
        LOGGER.info("DriverController.getOriginCity params:{}", cityName);
        RestfulResponse<List<OriginationCityVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), "success", null);
        try {
            result = integrationUtil.getOriginationCity(cityName);
        } catch (BaseException be) {
            LOGGER.error("DriverController.getOriginCity error:{}", be.getMessage());
            result.setMessage(be.getMessage());
            result.setCode(CommonEnum.ERROR.getCode());
        } catch (Exception e) {
            LOGGER.error("DriverController.getOriginCity error:{}", e.getMessage());
            result.setMessage("操作失败");
            result.setCode(CommonEnum.ERROR.getCode());
        }
        return result;
    }

    @PostMapping(value = "/updateDeleteStatus")
    @ApiOperation(value = "恢复司机删除状态", notes = "恢复司机删除状态", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Object.class)})
    public RestfulResponse<List<String>> updateDeleteStatus(@RequestBody List<Long> driverIds,
                                                            @RequestHeader("Authorization") String token) {
        LOGGER.info("DriverController.updateDeleteStatus（恢复司机删除状态） params : {} ", driverIds);
        RestfulResponse<List<String>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum
                .SUCCESS.getText(), null);
        try {
            List<String> msgs = driverService.updateDeleteStatus(driverIds, token);
            if (!CollectionUtils.isEmpty(msgs)) {
                result = new RestfulResponse<>(CommonEnum.ERRORLIST.getCode(), "部分司机删除失败", msgs);
            }
        } catch (BaseException e) {
            LOGGER.error("DriverController.updateDeleteStatus BaseException {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.updateDeleteStatus ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        }
        return result;
    }


    /**
     * 车辆报班 列表查询--PC
     */
    @PostMapping("/queryChekinList")
    @ApiOperation(value = "车辆报班 列表查询", notes = "车辆报班 列表查询", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Object.class)})
    public RestfulResponse<Page<DriverCheckinDTO>> queryChekinList(@RequestBody Page<DriverCheckinDTO> page) {
        RestfulResponse<Page<DriverCheckinDTO>> response = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        try {
            Page<DriverCheckinDTO> list = driverCheckinService.queryCheckinList(page);
            response.setData(list);
        } catch (BaseException be) {
            LOGGER.error("DriverController.queryChekinList BaseException {}", be);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.queryChekinList error {}", e);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(CommonEnum.ERROR.getText());
        }
        return response;
    }

    /**
     * 查询司机信息
     * hotfix : 2018-9-20 如果司机OMS收到指令调整报班为已安排 /指令删除 调整报班为已失效
     */
    @GetMapping("/queryDriver/{id}/{checkinId}")
    @ApiOperation(value = "查询个人司机信息", notes = "查询个人司机信息", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Object.class)})
    public RestfulResponse<Driver> queryDriver(@PathVariable Long id, @PathVariable Long checkinId, HttpServletRequest request) {
        RestfulResponse<Driver> response = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        LOGGER.info("DriverController.driverToOtm（如果司机OMS收到指令调整报班为已安排 /指令删除 调整报班为已失效） params : {} ", id + "===" + checkinId);
        try {
            Driver driver = driverService.queryDriverCheckInStatus(id, checkinId, request);
            response.setData(driver);
        } catch (BaseException be) {
            LOGGER.error("DriverController.queryDriver BaseException {}", be);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.queryDriver error {}", e);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(CommonEnum.ERROR.getText());
        }
        return response;
    }

    /**
     * @param lspId
     * @return
     */
    @GetMapping("/driverToOtm/{lspId}")
    @ApiOperation(value = "司机信息推otm", notes = "司机信息推otm", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Object.class)})
    public RestfulResponse<Object> driverToOtm(@PathVariable Long lspId) {
        LOGGER.info("DriverController.driverToOtm（司机信息推otm） params : {} ", lspId);
        RestfulResponse<Object> response = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        try {
            Wrapper<Driver> wrapper = new EntityWrapper<>();
            wrapper.eq("lsp_id", lspId);
            List<Driver> driverList = driverService.selectList(wrapper);
            for (Driver driver : driverList) {
                driverService.driverToOtm(driver.getId());
            }
        } catch (BaseException be) {
            LOGGER.error("DriverController.driverToOtm BaseException {}", be);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.driverToOtm error {}", e);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(CommonEnum.ERROR.getText());
        }
        return response;
    }

    /**
     * 报班推送otm
     */
    @GetMapping("/driverCheckinToOtm/{id}")
    @ApiOperation(value = "司机报班推otm", notes = "司机报班推otm", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Object.class)})
    public RestfulResponse<Object> driverCheckinToOtm(@PathVariable Long id, @RequestHeader("Authorization") String token) {
        LOGGER.info("DriverController.driverCheckinToOtm（司机报班推otm） params : {} ", id);
        RestfulResponse<Object> response = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        try {
            driverCheckinService.driverCheckinToOtm(id, token);
        } catch (BaseException be) {
            LOGGER.error("DriverController.driverCheckinToOtm BaseException {}", be);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.driverCheckinToOtm error {}", e);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(CommonEnum.ERROR.getText());
        }
        return response;
    }


    @GetMapping("/isUnlcnFleetDriver/{id}")
    @ApiOperation(value = "判断是否是中联创建的自由车队的司机", notes = "判断是否是中联创建的自由车队的司机", produces = MediaType.APPLICATION_JSON_VALUE, response
            = RestfulResponse.class)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "操作失败", response = Boolean.class)})
    public RestfulResponse<DriverToErpVO> isUnlcnFleetDriver(@PathVariable Long id, @RequestHeader("Authorization") String token) {
        LOGGER.info("DriverController.isUnlcnFleetDriver（判断是否是中联创建的自由车队的司机） params : {} ", id);
        RestfulResponse<DriverToErpVO> response = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(),
                CommonEnum.SUCCESS.getText(), null);
        try {
            DriverToErpVO driverToErpVO = driverService.isUnlcnFleetDriver(id, token);
            response.setData(driverToErpVO);
        } catch (BaseException be) {
            LOGGER.error("DriverController.isUnlcnFleetDriver BaseException {}", be);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.isUnlcnFleetDriver error {}", e);
            response.setCode(CommonEnum.ERROR.getCode());
            response.setMessage(CommonEnum.ERROR.getText());
        }
        return response;
    }

    /**
     * 根据司机名称获取司机信息
     *
     * @param arFundDTOSs
     * @return
     */
    @PostMapping(value = "/queryDriverByName")
    @ApiOperation(value = "获取司机信息", notes = "获取司机信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<Map<Long, Driver>> queryDriverByName(@RequestBody List<ArFundDTO> arFundDTOSs) {
        LOGGER.info("DriverController.queryDriverByName param : {}", arFundDTOSs);
        RestfulResponse<Map<Long, Driver>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(driverService.queryDriverByName(arFundDTOSs));
        } catch (BaseException e) {
            LOGGER.error("DriverController.queryDriverByName BaseException", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.queryDriverByName", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        }
        return result;
    }

    /**
     * 批量获取司机信息
     *
     * @param driverDTOs
     * @return
     */
    @PostMapping(value = "/getDriverAll")
    @ApiOperation(value = "批量获取司机信息", notes = "批量获取司机信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<List<Driver>> getDriverAll(@RequestBody List<Driver> driverDTOs) {
        LOGGER.info("DriverController.getDriverAll param : {}", driverDTOs);
        RestfulResponse<List<Driver>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(driverService.getDriverAll(driverDTOs));
        } catch (BaseException e) {
            LOGGER.error("DriverController.getDriverAll BaseException", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.getDriverAll", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        }
        return result;
    }

    /**
     * 导出运力信息 到excel
     */
    @PostMapping("/exportDriver")
    public RestfulResponse<List<DriverExportDTO>> exportDriver(@RequestBody Map<String, String> condition) {

        LOGGER.info("DriverController.exportDriver param : {}", condition);
        RestfulResponse<List<DriverExportDTO>> response = new RestfulResponse<>(0, "操作成功", null);
        try {
            List<DriverExportDTO> data = driverService.exportDriver(condition);
            response.setData(data);
        } catch (BaseException be) {
            LOGGER.error("DriverController.exportDriver BaseException:{}", be.getMessage());
            response.setCode(-1);
            response.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.exportDriver error:{}", e);
            response.setCode(-1);
            response.setMessage("系统异常");
        }
        return response;
    }

    /**
     * 获取司机信息
     *
     * @return
     */
    @GetMapping(value = "/queryDriverByCorpName")
    @ApiOperation(value = "获取司机信息", notes = "获取司机信息", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<List<Driver>> queryDriver(@RequestParam("corpName") String corpName) {
        LOGGER.info("DriverController.queryDriverByCorpName param : {}", corpName);
        RestfulResponse<List<Driver>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<Driver> drivers = driverService.queryDriverByCorpName(corpName);
            result.setData(drivers);
        } catch (BaseException e) {
            LOGGER.error("DriverController.queryDriverByCorpName BaseException {}", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.queryDriverByCorpName {}", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        }
        return result;
    }

    /**
     * 获取司机信息
     */
    @GetMapping(value = "/queryDriverWithFleet/{mobile}")
    @ApiOperation(value = "获取司机信息包含车队", notes = "获取司机信息包含车队", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<DriverDTO> queryDriverWithFleet(@PathVariable("mobile") String mobile) {
        LOGGER.info("DriverController.queryDriverWithFleet param : {}", mobile);
        RestfulResponse<DriverDTO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            DriverDTO driver = driverService.queryDriverWithFleet(mobile);
            result.setData(driver);
        } catch (BaseException e) {
            LOGGER.error("DriverController.queryDriverWithFleet BaseException {}", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.queryDriverWithFleet {}", e);
            result.setCode(CommonEnum.ERROR.getCode());
            result.setMessage(e.getMessage());
        }
        return result;
    }

    @PostMapping("/queryDriverBasic")
    @ApiOperation(value = "获取司机的基础信息", notes = "获取司机的基础信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public RestfulResponse<DriverBasicDTO> queryDriverBasic(@RequestBody Map<String, String> commonDTO) {
        RestfulResponse<DriverBasicDTO> res = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            DriverBasicDTO driverBasic = driverService.queryDriverBasic(commonDTO);
            res.setData(driverBasic);
        } catch (BaseException be) {
            LOGGER.error("DriverController.queryDriverBasic BaseException: {}", be);
            res.setCode(-1);
            res.setMessage(be.getMessage());
        } catch (Exception e) {
            LOGGER.error("DriverController.queryDriverBasic error: {}", e);
            res.setCode(-1);
            res.setMessage("系统异常");
        }
        return res;
    }

    @PostMapping(value = "/otmDriverCheckinLog")
    @ApiOperation(value = "获取司机报班传入OTM日志列表", notes = "获取司机报班传入OTM日志列表", produces = MediaType
            .APPLICATION_JSON_VALUE, response = RestfulResponse.class)
    public RestfulResponse<Page<DriverCheckinLineVO>> otmDriverCheckinLog(@RequestBody Page<DriverCheckinLineBO> page) {
        LOGGER.info("DriverController.otmDriverCheckinLog（获取司机报班传入OTM日志列表） params : {} ", page);
        RestfulResponse<Page<DriverCheckinLineVO>> result = new RestfulResponse<>(CommonEnum
                .SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            result.setData(driverCheckinService.otmDriverCheckinLog(page));
        } catch (BaseException e) {
            LOGGER.error("DriverController.otmDriverCheckinLog ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("DriverController.otmDriverCheckinLog ERROR {}", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(),
                    null);
        }
        return result;
    }

}